<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>业务机会</title>
<jsp:include page="../inc.jsp" flush="false"></jsp:include>

<script type="text/javascript"
        src="${pageContext.request.contextPath}/plug-in/custom/selectorCrm/businessOpportunitiesSel.js"
        charset="utf-8"></script>
        <script type="text/javascript"
        src="${pageContext.request.contextPath}/plug-in/custom/selectorInventory/productSel.js"
        charset="utf-8"></script>
<script type="text/javascript"
        src="${pageContext.request.contextPath}/app/crm/salesOfProductsList.js"
        charset="utf-8"></script>
<script type="text/javascript"
        src="${pageContext.request.contextPath}/app/crm/salesOfProductsForm.js"
        charset="utf-8"></script>
<script type="text/javascript">
Ext.onReady(function () {
    Ext.QuickTips.init();
    createForm();
    businessOpportunitiesForm = Ext.create('businessOpportunitiesForm');
    businessOpportunitiesForm.getForm().load({

        url: getRootPath()+"/businessOpportunitiesController/info.action",
        method: "POST",
        params: {
            id: '<%=request.getParameter("Id")%>'
        },
        waitTitle:'提示',
        waitMsg:'正在处理您的请求,请稍候...',
        success:function(form,action){
            if(form.findField("signDate").getValue()!=null && form.findField("signDate").getValue()!="") {
                form.findField("signDate").setValue(new Date(parseInt(form.findField("signDate").getValue() )).format("yyyy-MM-dd"))
            }
            form.findField("customerName").setValue(action.result.data.customers.company.toString());
            createLayout();
        }

    });
});

var  businessOpportunitiesForm, tabPanel;
// 创建form表单
function createForm() {
    Ext.define('businessOpportunitiesForm', {
        extend : 'Ext.form.Panel',
        fields : new Ext.util.MixedCollection(),
        initComponent : function() {
            this.fields.add('id', new Ext.form.Hidden({
                name : 'id',
                dataIndex : 'id'
            }));
            this.fields.add('deleteFlag', new Ext.form.Hidden({
                name : 'deleteFlag',
                dataIndex : 'deleteFlag'
            }));
            this.fields.add('bussName', new Ext.form.DisplayField({
                name : 'bussName',
                dataIndex : 'bussName',
                fieldLabel : '业务机会名',
                allowBlank : false
            }));
            this.fields.add('signDate',new Ext.form.DisplayField({
                name : 'signDate',
                dataIndex : 'signDate',
                fieldLabel : '结束日期',
                allowBlank : false
            }));
            this.fields.add('phase', new Ext.form.DisplayField({
                name : 'phase',
                dataIndex : 'phase',
                fieldLabel : '阶段',
                allowBlank : false
            }));
            this.fields.add('chance', new Ext.form.DisplayField({
                name : 'chance',
                dataIndex : 'chance',
                allowDecimals : false,
                decimalPrecision : null,
                fieldLabel : '成交概率(%)',
                allowBlank : true
            }));
            this.fields.add('source', new Ext.form.DisplayField({
                name : 'source',
                dataIndex : 'source',
                allowDecimals : false,
                decimalPrecision : null,
                fieldLabel : '来源',
                allowBlank : true
            }));
            this.fields.add('money', new Ext.form.DisplayField({
                name : 'money',
                dataIndex : 'money',
                allowDecimals : true,
                decimalPrecision : 2,
                fieldLabel : '金额',
                allowBlank : true
            }));
            this.fields.add('remark', new Ext.form.TextArea({
                name : 'remark',
                dataIndex : 'remark',
                fieldLabel : '备注',
                allowBlank : true
            }));
            this.fields.add('customerId', new Ext.form.Hidden({
                name: 'customerId',
                dataIndex: 'customerId'
            }));
            this.fields.add('btnCustomersId', new Ext.Button({
                name: 'btnCustomersId',
                dataIndex: 'btnCustomersId',
                iconCls: 'searchIcon',
                handler: function () {
                    selCustomer();
                },
                width: 25
            }));
            this.fields.add('customerName', new Ext.form.DisplayField({
                name: 'customerName',
                dataIndex: 'customerName',
                fieldLabel: '客户名称',
                readOnly:true,
                emailText:'请选择客户',
                width: 230,
                allowBlank: false
            }));

            this.items = [ this.fields.get('id'),this.fields.get('deleteFlag'),
                {
                    xtype: 'container',
                    layout: 'hbox',
                    margin: '0 0 5 0',
                    defaults: {
                        flex: 1,
                        hideLabel: true
                    }, items: [{
                    xtype: 'container',
                    layout: 'hbox',
                    margin: '0 0 5 0',
                    defaults: {

                        hideLabel: true
                    }, items: [ this.fields.get('customerId'),this.fields.get('customerName'),this.fields.get('btnCustomersId')]}]},{
                    xtype: 'container',
                    layout: 'hbox',
                    margin: '0 0 5 0',
                    defaults: {
                        flex: 1,
                        hideLabel: true
                    }, items: [ this.fields.get('bussName'),this.fields.get('signDate')]},{
                    xtype: 'container',
                    layout: 'hbox',
                    margin: '0 0 5 0',
                    defaults: {
                        flex: 1,
                        hideLabel: true
                    }, items: [ this.fields.get('phase'),this.fields.get('chance')]},{
                    xtype: 'container',
                    layout: 'hbox',
                    margin: '0 0 5 0',
                    defaults: {
                        flex: 1,
                        hideLabel: true
                    }, items: [ this.fields.get('source'),this.fields.get('money')]},{
                    xtype: 'container',
                    layout: 'hbox',
                    margin: '0 0 5 0',
                    defaults: {
                        flex: 1,
                        hideLabel: true
                    }, items: [ this.fields.get('remark'),null]} ];
            this.xtype= 'form';
            this.frame = false;
            this.border = true;
            this.split = true;
            this.autoScroll=true,
                    this.bodyPadding= 10,
                    this.bodyBorder= true;
            this.fieldDefaults= {
                labelWidth: 80,
                labelAlign:'right',
                msgTarget: 'side'
            };
            this.defaults={
                anchor: '100%'
            };
            this.callParent(arguments);
        },
        onRender : function() {
            this.callParent(arguments);
        },
        newDataRecord : function() {
            this.getForm().reset();
            var   customersId = <%=request.getParameter("customersId")%>;
            if(customersId!=null)  {
            	businessOpportunitiesForm.getForm().findField("customerId").setValue(<%=request.getParameter("customersId")%>);
            	businessOpportunitiesForm.getForm().findField("customerName").setValue('<%=request.getParameter("customersName")%>');
            }
        }
    });
}





// 创建layout
function createLayout() {
    tabPanel= Ext.create('Ext.tab.Panel', {
        activeTab: 0,                       //指定默认的活动tab
        plain: true,                        //True表示tab候选栏上没有背景图片（默认为false）
        enableTabScroll: true,              //选项卡过多时，允许滚动
        defaults: { autoScroll: true },
        layout: 'fit',
        listeners:{
            tabchange:function(tp,p){

            }
        } ,
        items: [{
            id: "tab1",
            title: '详细信息',
            items:[businessOpportunitiesForm],
            closable: false                  //这个tab可以被关闭
        },{
            id: "tab2",
            layout: 'fit',
            title: '计划的活动',

            html : '<iframe scrolling="auto" frameborder="0"   width="100%" height="100%" src="programActivities.jsp?entityID=<%=request.getParameter("Id")%>"></iframe>'
        },{
            id: "tab3",
            layout: 'fit',
            title: '产品',
            items:[Ext.create('App.crm.salesOfProductsList')]
        } , {
            id: "tab4",
            title: '附件',

            html : '<iframe scrolling="auto" frameborder="0"   width="100%" height="100%" src="${pageContext.request.contextPath}/upload/attachment.jsp?businessKey=<%=request.getParameter("Id")%>"></iframe>'
        }]
    });
    var viewport = new Ext.Viewport({
        layout: 'fit',
        region: 'center',
        border: false,
        items: [
            tabPanel
        ]
    });
    viewport.doLayout();
}
</script>
</head>
<body>
</body>
</html>